class Solution {
  public:

    int MLS(vector<int>& arr) {
        int cur_ans = 1, max_ans = 1;
        sort(arr.begin(), arr.end());
        for (int i = 0; i < arr.size() - 1; i++) {
            if (arr[i] + 1 == arr[i + 1]) {
                ++cur_ans;
            } else if(arr[i] != arr[i + 1]){
                if (max_ans <= cur_ans) {
                    max_ans = cur_ans;
                }
                cur_ans = 1;
            }
        }
        if (max_ans <= cur_ans) {
            max_ans = cur_ans;
        }
        return max_ans;
    }
};